<script lang="ts" setup>
import { ref } from "vue";
import { useRouter, useRoute } from "vue-router";
import "element-plus/theme-chalk/display.css";
const msgNumber = ref(1); // 大于 99 设置 99+
const router = useRouter();
const route = useRoute();
const List = router
  .getRoutes()
  // @ts-ignore
  .filter((item) => item.meta.location?.includes("header"));
const MenuList = ref(List);
console.log(List);
function toLink(item: string) {
  router.push(item);
}
const show = ref(false);
function showUserInfo() {
  show.value = true;
}
function leaveUserInfo() {
  show.value = false;
}

const isFullScreen = ref(false);

function toggleFullScreen() {
  const docElm = document.documentElement;
  if (!isFullScreen.value) {
    if (docElm.requestFullscreen) {
      docElm.requestFullscreen();
      // @ts-ignore
    } else if (docElm.mozRequestFullScreen) {
      // @ts-ignore
      docElm.mozRequestFullScreen();
      // @ts-ignore
    } else if (docElm.webkitRequestFullscreen) {
      // @ts-ignore
      docElm.webkitRequestFullscreen();
      // @ts-ignore
    } else if (docElm.msRequestFullscreen) {
      // @ts-ignore
      docElm.msRequestFullscreen();
    }
  } else {
    if (document.exitFullscreen) {
      document.exitFullscreen();
      // @ts-ignore
    } else if (document.mozExitFullScreen) {
      // @ts-ignore
      document.mozExitFullScreen();
      // @ts-ignore
    } else if (document.webkitExitFullscreen) {
      // @ts-ignore
      document.webkitExitFullscreen();
      // @ts-ignore
    } else if (document.msExitFullscreen) {
      // @ts-ignore
      document.msExitFullscreen();
    }
  }
  isFullScreen.value = !isFullScreen.value;
}

function logOut() {
  router.replace("/login");
}
</script>
<template>
  <div class="header">
    <el-affix :offset="0">
      <div class="header-row">
        <div class="row" style="width: 233px; padding-left: 10px">
          <el-icon color="#3A75F3" :size="35">
            <Shop />
          </el-icon>
          <span style="font-size: 18px; font-weight: bolder">仓储管理系统</span>
        </div>
        <div class="list row">
          <div
            class="tag-button"
            v-for="item in MenuList"
            :key="item.path"
            @click="toLink(item.path)"
            :class="route.path.includes(item.path) ? 'select' : ''"
          >
            <span>{{ item.meta.title }}</span>
          </div>
        </div>
        <div style="width: 233px" class="row tool">
          <div class="tool-left">
            <el-tooltip
              class="box-item"
              effect="light"
              content="未读消息"
              placement="bottom"
            >
              <el-icon size="18">
                <Bell /> <span>{{ msgNumber }}</span>
              </el-icon>
            </el-tooltip>

            <el-tooltip
              class="box-item"
              effect="light"
              content="全屏缩放"
              placement="bottom"
            >
              <el-icon size="18" @click="toggleFullScreen">
                <FullScreen />
              </el-icon>
            </el-tooltip>

            <!-- <el-icon size="18"><Lock /></el-icon> -->
          </div>
          <div class="head" @click="showUserInfo">
            <el-avatar size="small" />
            <span>爆炸💥</span>
          </div>
          <div v-show="show" @mouseleave="leaveUserInfo" class="user-info">
            <el-button @click="logOut">退出登录</el-button>
          </div>
        </div>
      </div>
    </el-affix>
  </div>
</template>
<style lang="less" scoped>
.header {
  width: 100%;
  background-color: #e6e7ee;
  position: -webkit-sticky;
  /* For Safari */
  position: sticky;
  top: 56px;
  font-size: 20px;
}

.header-row {
  width: 100%;
  height: 56px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.list {
  width: 960px;
  height: 44px;
  margin-top: 12px;

  .tag-button {
    width: 120px;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;

    span {
      font-size: 16px;
      cursor: pointer;
    }
  }

  .select {
    color: #6265f6;
    border-top-left-radius: 5px;
    border-top-right-radius: 5px;
    background-color: #fff;
  }
}

.logo {
  width: 35px;
  height: 35px;
  margin-top: -12px;
  background-color: #5092f5;
}

.row {
  width: auto;
  display: flex;
  flex-direction: row;
  align-items: center;
}

.tool {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;

  .user-info {
    background-color: #fff;
    position: absolute;
    top: 56px;
    width: 120px;
    height: 200px;
    right: 10px;
    border: 1px solid #888;
    border-radius: 10px;
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .head {
    width: 127px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    cursor: pointer;

    span {
      font-size: 15px;
    }
  }
}

.tool-left {
  width: 140px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-right: 2px solid #999;

  i {
    cursor: pointer;
  }

  span {
    position: absolute;
    width: 15px;
    height: 15px;
    background-color: red;
    border-radius: 50%;
    font-size: 9px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    margin-right: -13px;
    margin-top: -13px;
    opacity: 0.7;
    font-weight: bolder;
    font-family: "Courier New", Courier, monospace;
  }

  span:hover {
    transform: scale(2);
  }
}
</style>
